var http = require('http') ;
var url = require('url');//使用内置的url模块
// http.createServer (function(req , res){
// 	res.writeHead (200 , {'Content-type':'text/plain'});
// 	res.write('Hello World');
// 	console.log('ok');
// 	res.end() ;
// }).listen(8888) ;


//针对server 做一次封装 并且导出 以便其他模块调用 

var http=require('http');//使用内置nodejs内置的http模块
function start(route , handle ){
    function onRequest(request,response){
    	var postData = '';
    	var pathname = url.parse(request.url).pathname ;

    	request.setEncoding('utf8');
    	request.addListener('data' , function(postDataChunk){
    		postData += postDataChunk ;
    		console.log('data==========' + postDataChunk);
    	}) ;
    	request.addListener('end' , function(){
    		 route(handle , pathname , response , postData );
    	});
	   
	    //交给 route 做 response 
	    // response.writeHead(200,{"Content-Type":"text/plain"});
	    // response.write("Hello World");
	    // response.end();
	}
    http.createServer(onRequest).listen(8888);
    console.log('服务器已经启动！');
}

exports.start=start;//将start这个功能开放出来，这样就能在index.js中使用它
